package zhh.tangbao.commodity.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import zhh.tangbao.commodity.entity.CommodityOrder;
import zhh.tangbao.system.vo.SelectOptionsVo;
import zhh.tangbao.wechat.vo.WeChatCommodityOrderVo;
import zhh.tangbao.wechat.dto.WeChatOrderQueryDto;
import zhh.tangbao.wechat.vo.order.OrderDetailVo;

import java.util.List;

/**
 * <p>
 *     描述
 * </p>
 * @author 粥灰灰
 * <p>2023/3/4</p>
 */

@Repository
@Mapper
public interface CommodityOrderDao extends BaseMapper<CommodityOrder> {

    List<WeChatCommodityOrderVo> wechatPage(WeChatOrderQueryDto dto);

    /**
     * 如果订单仍处于待付款状态则取消订单
     * @return
     */
    @Update("UPDATE commodity_order SET order_status = #{orderStatus} WHERE id = #{orderId}")
    int cancelOrderIfNotPayment(@Param("orderId") String orderId, @Param("orderStatus") Integer orderStatus);

    @Select("SELECT order_status integer_key FROM commodity_order GROUP BY order_status")
    List<SelectOptionsVo> getOrderStatusGroupByOrderStatus();

    @Select("SELECT record_user_id FROM commodity_order WHERE id = #{id}")
    String getRecordUserIdById(@Param("id") String orderId);

    @Select("SELECT id, order_status, payment_time, order_total_price, record_time FROM commodity_order WHERE id = #{id}")
    OrderDetailVo getOrderDetailVoById(@Param("id") String id);
}
